﻿using System;
using System.Collections.Generic;
using System.Text;
using WeChatSDK.Common.Enums.MiniProgram;

namespace WeChatSDK.WeChatServiceComponent.MiniProgram
{
    /// <summary>
    /// 微信小程序服务
    /// </summary>
    public class MiniProgramService
    {
        /// <summary>
        /// 小程序卡片跳转小程序代码模板
        /// </summary>
        private const string CALL_MINI_PROGRAMP_BY_CAR = "<mp-miniprogram data-miniprogram-appid=\"{0}\" data-miniprogram-path=\"{1}\" data-miniprogram-title=\"{2}\" data-progarm-imageurl=\"{3}\"></mp-miniprogram>";
        /// <summary>
        /// 文字跳转小程序代码模板
        /// </summary>
        private const string CALL_MINI_PROGRAMP_BY_TEXT = "<p><a data-miniprogram-appid=\"{0}\" data-miniprogram-path=\"{1}\" href=\"\">{2}</a></p>";
        /// <summary>
        /// 图片跳转小程序代码模板
        /// </summary>
        private const string CALL_MINI_PROGRAMP_BY_IMAGE = "<p><a data-miniprogram-appid=\"{0}\" data-miniprogram-path=\"{1}\" href=\"\"><img src=\"{2}\" alt=\"\" data-width=\"null\" data-ratio=\"NaN\"></a></p>";

        /// <summary>
        /// 获取可插入微信图文内容中的小程序代码
        /// </summary>
        /// <param name="miniProgramCodeType">小程序代码类型</param>
        /// <param name="miniProgramAppId">小程序的AppID</param>
        /// <param name="miniProgramPagePath">小程序要打开的路径</param>
        /// <param name="miniProgramTitle">小程序卡片的标题，不超过35个字</param>
        /// <param name="miniProgramImageUrl">小程序卡片的封面图链接，图片必须为1080*864像素</param>
        /// <returns></returns>
        public string GetMiniProgramCallCode(MiniProgramCodeType miniProgramCodeType, string miniProgramAppId, string miniProgramPagePath, string miniProgramTitle, string miniProgramImageUrl)
        {
            if (miniProgramCodeType == MiniProgramCodeType.MiniProgramCard)
            {
                return string.Format(CALL_MINI_PROGRAMP_BY_CAR, miniProgramAppId, miniProgramPagePath, miniProgramTitle, miniProgramImageUrl);
            }
            if (miniProgramCodeType == MiniProgramCodeType.Image)
            {
                return string.Format(CALL_MINI_PROGRAMP_BY_IMAGE, miniProgramAppId, miniProgramPagePath, miniProgramTitle);
            }

            return string.Format(CALL_MINI_PROGRAMP_BY_TEXT, miniProgramAppId, miniProgramPagePath, miniProgramImageUrl);

        }
    }
}
